<template>
	<div class="page createTemporary-page" data-page="createTemporaryTask" style="z-index: 2">
		<div class="link-page-nav">
			<a href="#" class="link" @click=$root.backToTab()> <i class="iconfont icon-zuo"></i>
			</a>
		</div>
		<div class="link-page-top">
			<div class="link-page-title">创建临时任务</div>
		</div>
		<div class="page-content" style="padding: 0 20px 120px 20px;" id="kalarm">
			<div class="inView">
				<textarea class="inDes cancle-ios-write" id="desc" placeholder="输入任务内容，尝试用语音输入更便捷" required="required"
					name="bjms"></textarea>
				<i class="iconfont icon-yuyin" id="crTb_inputDetails"></i>
			</div>
			<div class="inItem">
				<div>业主单位<label>(必选)</label></div>
				<a href="#" id="temporaryTask_select_org"><span id="temporaryTask_org">选择任务所在的业主单位</span><i
						class="iconfont icon-jiantou" id="temporaryTask_arr_org"></i></a>
			</div>
			<div class="inItem">
				<div>主责任人<label>(必选)</label></div>
				<a href="#" id="selectTemporaryOwner" @click="select_tip">
					<span id="temporaryOwner">选择主责任人（单选）</span>
					<i class="iconfont icon-jiantou"></i>
				</a>
			</div>
			<div class="inItem">
				<div>参与人员</div>
				<a href="#" id="selectTemporaryJoner" @click="select_tip"><span
						id="temporaryJoiner">选择其他参与人员（多选）</span><i class="iconfont icon-jiantou"></i></a>
			</div>
			<div class="inItem">
				<div>知会人</div>
				<a href="#" id="selectTemporaryKnower" @click="select_tip"><span id="temporaryKnower">选择知会人（多选）</span><i
						class="iconfont icon-jiantou"></i></a>
			</div>
			<div class="inItem">
				<div>审核人<label>(必选)</label></div>
				<a href="#" id="selectTemporaryApper" @click="select_tip"><span id="temporaryApper"></span><i
						class="iconfont icon-jiantou"></i></a>
			</div>
			<div class="inItem">
				<div>截止时间<label>(必选)</label></div>
				<a href="#" @click="openTime()"><span id="temporaryTask_time">选择整改期限</span><i
						class="iconfont icon-jiantou"></i></a>
			</div>

			<div class="submitBtn" @click="viewBlak_update()">创建</div>
		</div>
	</div>
</template>

<script>
	return {
		mounted() {
			var self = this;
			var app = self.$app;
		},
		data: function () {
			return {
				taskTime: "",
				currentOrgId: "", //业主单位
				dutyMan: "",
				partMan: "",
				tellMan: "",
				verifyMan: userInfor.accountName,
				selectOptionIndex1: 0,
				selectOptionIndex2: "",
				selectOptionIndex3: "",
				selectOptionIndex4: null,
				selectOptionType: null,
			}
		},
		methods: {
			viewBlak_update: function () { //提交数据
				var self = this;
				var formData = app.form.convertToData('#kalarm');
				var bjms = jQuery.trim(formData.bjms);
				if (bjms == "") {
					app.methods.showToastCenter("请填写描述");
					return;
				}
				if (self.currentOrgId == "") {
					app.methods.showToastCenter("请选择业主单位");
					return;
				}
				if (self.dutyMan == "") {
					app.methods.showToastCenter("请选择责任人");
					return;
				}
				if (self.verifyMan == "") {
					app.methods.showToastCenter("请选择审核人");
					return;
				}
				if (self.taskTime == "") {
					app.methods.showToastCenter("请选择截止时间");
					return;
				}
				common.loading(1);
				Dao.addTempTask({
					userName: userInfor.accountName,
					deviceId: appKeyObj.deviceId,
					orgId: self.currentOrgId, //142
					status: 1,
					createAccount: userInfor.accountName,
					dutyMan: self.dutyMan, //主责人账号
					partMan: self.partMan, //参与人账号
					tellMan: self.tellMan, //知会人账号
					verifyMan: self.verifyMan, //审核人
					content: bjms,
					endtimeStr: self.taskTime + ":00",
				}, function (data) {
					common.loading(0);
					app.methods.showToastCenter("操作成功");
					// app.router.back();
					app.methods.backToTab();
					// app.view.current.el.f7View.router.currentPageEl.f7Component.refreshCurrentLevel();
				}, true);
			},
			//初始化联网单位
			temporaryTaskInitOrg: function () {
				var self = this;
				if (userInfor.isMuilUnitUser == 1) { //多联网单位角色
					jQuery("#temporaryTask_select_org").show().click(function (e) {
						loadSelectUnitFunc(function (data) {
							if (self.selectOptionOrg != data.orgId) {
								self.selectOptionOrg = data.orgId;
								self.currentOrgId = data.orgId;
								jQuery("#temporaryTask_org").html(data.orgName);
								$("#temporaryTask_org").css("color", "#333333");
							} else {
								self.selectOptionOrg = 0;
								if (single_Orgid == "") {
									self.currentOrgId = userInfor.organizationIds;
								} else {
									self.currentOrgId = single_Orgid;
								}
							}
						}, self.selectOptionOrg);
					});
				} else { //单联网单位角色
					$("#temporaryTask_arr_org").hide();
					self.currentOrgId = single_Orgid;
					jQuery("#temporaryTask_org").html(single_OrgName);
					$("#temporaryTask_org").css("color", "#333333");
				}
			},
			initTbPiker: function () {
				var self = this;
				$("#crTb_inputDetails").click(function (e) {
					//第二个参数是否需要保存语音
					native.startVoice("desc", false);
				});
			},
			//语音输入回调
			voiceCollectionData: function (voiceStr, componentId) {
				var text = $("#" + componentId).val();
				if (!voiceStr || "" === voiceStr.trim()) {
					app.methods.showToastCenter("未能识别您说的语音,请重试。");
				} else {
					$("#" + componentId).val(text + voiceStr);
				}
			},
			openTime: function () {
				var self = this;
				loadSelectedDate_Fn(1, function (data) {
					$("#temporaryTask_time").html(data.singleDate);
					self.taskTime = data.singleDate;
				});
			},
			/*责任人*/
			htmlGetUnitUsers: function () {
				var self = this;
				self.selectOptionIndex1 = "";
				self.selectOptionIndex2 = "";
				self.selectOptionIndex3 = "";
				self.selectOptionIndex4 = null;
				self.selectOptionType = null;
				//人员名单
				jQuery("#selectTemporaryOwner").click(function (e) {
					if (!self.currentOrgId || self.currentOrgId.toString().split(",").length != 1) {
						app.methods.showToastCenter('请选择单位');
						return;
					}
					getFourTypeUser(self.currentOrgId, function (data) {
						if (self.selectOptionIndex1 != data.index) {
							self.dutyMan = data.id;
							self.selectOptionIndex1 = data.index;
							self.selectOptionType = data.type;
							$("#temporaryOwner").html(data.name);
							$("#temporaryOwner").css("color", "#333");
						} else {
							self.dutyMan = "";
							self.selectOptionIndex1 = "";
							self.selectOptionType = 1;
							$("#temporaryOwner").html("请选择责任人（单选）");
							$("#temporaryOwner").css("color", "rgba(153, 153, 153, 1)");
						}
						self.dutyMan=self.selectOptionIndex1;
					}, self.selectOptionIndex1, self.selectOptionType);
				});

				//多选  参与人员
				jQuery("#selectTemporaryJoner").click(function (e) {
					if (!self.currentOrgId || self.currentOrgId.toString().split(",").length != 1) {
						app.methods.showToastCenter('请选择单位');
						return;
					}
					getFourTypeUser(self.currentOrgId, function (data) {
						if (data.index) {
							self.partMan = data.id;
							self.selectOptionIndex2 = data.index;
							self.selectOptionType = data.type;
							$("#temporaryJoiner").css("color","#333").html(data.name);
						}else{
							self.partMan = "";
							self.selectOptionIndex2 = "";
							self.selectOptionType = "";
							$("#temporaryJoiner").css("color","rgba(153, 153, 153, 1)").html("选择其他参与人员（多选）");
						}
					}, self.selectOptionIndex2, self.selectOptionType,true);
				});

				//多选 知会人
				jQuery("#selectTemporaryKnower").click(function (e) {
					if (!self.currentOrgId || self.currentOrgId.toString().split(",").length != 1) {
						app.methods.showToastCenter('请选择单位');
						return;
					}
					getFourTypeUser(self.currentOrgId, function (data) {
						if (data.index) {
							self.tellMan = data.id;
							self.selectOptionIndex3 = data.index;
							self.selectOptionType = data.type;
							$("#temporaryKnower").css("color","#333").html(data.name);
						}else{
							self.tellMan = "";
							self.selectOptionIndex3 = "";
							self.selectOptionType = "";
							$("#temporaryKnower").css("color","rgba(153, 153, 153, 1)").html("选择其他参与人员（多选）");
						}
					}, self.selectOptionIndex3, self.selectOptionType, true);
				});

				jQuery("#selectTemporaryApper").click(function (e) {
					if (!self.currentOrgId || self.currentOrgId.toString().split(",").length != 1) {
						app.methods.showToastCenter('请选择单位');
						return;
					}
					getFourTypeUser(self.currentOrgId, function (data) {
						//这里是选择责任人之后的回调
						if (self.selectOptionIndex4 != data.index) {
							self.selectOptionIndex4 = data.index;
							self.selectOptionType = data.type;
							$("#temporaryApper").html(data.name);
							$("#temporaryApper").css("color", "#333")
						} else {
							self.selectOptionIndex4 = "";
							self.selectOptionType = 1;
							$("#temporaryApper").html("请选择审核人（单选）");
							$("#temporaryApper").css("color", "rgba(153, 153, 153, 1)")
						}
						self.verifyMan = self.selectOptionIndex4;
					}, self.selectOptionIndex4, self.selectOptionType);
				});
			},
			select_tip: function () {
				var self = this;
				if (self.currentOrgId == "" || self.currentOrgId == undefined) {
					app.methods.showToastCenter("请先选择业主单位");
					return;
				}
			},
		},
		on: {
			pageInit: function (e, page) {
				var self = this;
				$("#temporaryApper").html(userInfor.name + "（单选）");

				self.initTbPiker();
				self.temporaryTaskInitOrg();
				self.htmlGetUnitUsers();
			},
			pageAfterIn: function (e, page) {
				var self = this;
			}
		}
	}
</script>